﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using jsm.SqlHelper;
using System.Data;
using Lucene.Models;

namespace Lucene.Controllers
{
    public class SearchController : Controller
    {
        //
        // GET: /Search/

        [HttpPost]
        public ActionResult Index(string  model)
        {
            List<Employee> empList = new List<Employee>();
            Employee emp = null;
            using (SqlServerHelper helper = new SqlServerHelper()) {
                
                helper.Open();
               
                helper.Command.Parameters.Clear();
                helper.Command.CommandText = "select * from [Employees]";
                DataTable  dt  = helper.ReadTable();
                if (dt != null && dt.Rows.Count > 0) {
                    foreach (DataRow item in dt.Rows) {
                        emp = new Employee();
                        emp.EmployeeID = int.Parse(item["EmployeeID"].ToString());
                        emp.FirstName = item["FirstName"].ToString();
                        emp.LastName = item["LastName"].ToString();
                        emp.Title = item["Title"].ToString();
                        emp.TitleOfCourtesy = item["TitleOfCourtesy"].ToString();
                        emp.BirthDate = DateTime.Parse(item["BirthDate"].ToString());
                        empList.Add(emp);
                    }
                }

            }
            return View(empList.ToArray());
        }

        public ActionResult Index() {
            return View();
        }

       

    }
}
